home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8136 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.7 KB  |  128 lines

  1. Path: mavetju.iaehv.nl!edwin
  2. From: edwin@mavetju.iaehv.nl (Edwin Groothuis)
  3. Newsgroups: comp.lang.c,comp.os.os2.programmer.misc,comp.programming,fido7.os2.prog,sfnet.atk.os2
  4. Subject: Re: Playing *.wav files with OS/2
  5. Distribution: world
  6. Message-ID: <825627040edwin.term@mavetju.iaehv.nl>
  7. Sender: term@mavetju.iaehv.nl
  8. Date: Thu, 29 Feb 96 20:50:40 GMT
  9. References: <4h2fap$9sa@nic.dataphone.se>
  10. Organization: MavEtJu software, the Netherlands
  11. X-Newsreader: TRN for OS/2
  12.  
  13. In article <4h2fap$9sa@nic.dataphone.se> skorpio@dataphone.se writes:
  14. >If anyone could help me with playing *.wav files in OS/2. What I want to
  15. >do is that when the user presses a dialog button the utility plays a tune
  16. >( a .wav file ). 
  17.  
  18. #define     INCL_OS2MM
  19. #define     INCL_MCIOS2
  20. #define     INCL_DOSPROCESS
  21.  
  22. #include    <os2emx.h>
  23. #include    <mmos2/os2me.h>                     <-- do you have this?
  24. #include    <stdio.h>
  25. #include    <malloc.h>
  26. #include    <stdlib.h>
  27. #include    <strings.h>
  28. #include    "mmedia.h"
  29.  
  30.  
  31. typedef struct THREADINFO { ULONG ulSzStruct;
  32.                             BOOL bKillThread;
  33.                             HAB habThread;
  34.                             BOOL bThreadDead;
  35.                             BOOL bResult;
  36.                           } THREADINFO,*PTHREADINFO;
  37. typedef struct WAVTHREADINFO { THREADINFO ti;
  38.                                CHAR     WavFile[100];
  39.                                BOOL     continues;
  40.                              } WAVTHREADINFO, *PWAVTHREADINFO;
  41.  
  42.  
  43. ULONG MCIinterface(char *buff)
  44. {
  45.     const   rsize = 128;
  46.     char    rbuff[rsize];
  47.     ULONG   rc;
  48.  
  49.     bzero(rbuff,rsize);
  50.  
  51.     rc  =  mciSendString(buff,   /* buffer with MCI string */
  52.                          rbuff,  /* return buffer */
  53.                          rsize,  /* rbuff size */
  54.                          0,      /* no callback window handle */
  55.                          0);     /* no user parameter */
  56.     if (rc == MCIERR_SUCCESS)
  57.         if (rbuff[0]!='1')
  58.             return 1;
  59.     return (rc);
  60. }
  61.  
  62.  
  63. void    openPlayWavThread(PWAVTHREADINFO potiInfo)
  64. {
  65.     HAB     hab;
  66.     HMQ     hmq;
  67.  
  68.     hab=WinInitialize(0);
  69.     hmq=WinCreateMsgQueue(hab,0);
  70.     WinCancelShutdown(hmq,TRUE);
  71.  
  72.     potiInfo->ti.habThread=hab;
  73.     potiInfo->ti.bThreadDead=FALSE;
  74.     potiInfo->ti.bResult=FALSE;
  75.  
  76.     {
  77.         char    s[100];
  78.  
  79.         if (MCIinterface("open waveaudio alias wave shareable wait")!=0)
  80.             return;
  81.         sprintf(s,"load wave %s",potiInfo->WavFile);
  82.         MCIinterface(s);
  83.         MCIinterface("play wave wait");
  84.         MCIinterface("close wave wait");
  85.     }
  86.     WinDestroyMsgQueue(hmq);
  87.     WinTerminate(hab);
  88. /*    DosEnterCritSec();*/
  89. }
  90.  
  91.  
  92. void    PlayWav(char *wav,BOOL continues)
  93. {
  94.     THREADINFO ptiInput;
  95.     PVOID pfnThread;
  96.     PVOID pvParm;
  97.     PWAVTHREADINFO potiInfo;
  98.     static PWAVTHREADINFO WavThreadInfo=NULL;
  99.  
  100.     ptiInput.bKillThread=FALSE;
  101.  
  102.     ptiInput.ulSzStruct=sizeof(WAVTHREADINFO);
  103.     potiInfo=(PWAVTHREADINFO)malloc(sizeof(WAVTHREADINFO));
  104.     memcpy(potiInfo,&ptiInput,sizeof(THREADINFO));
  105.     pfnThread=openPlayWavThread;
  106.     pvParm=(PVOID)potiInfo;
  107.     strcpy(potiInfo->WavFile,wav);
  108.     potiInfo->continues=continues;
  109.     WavThreadInfo=potiInfo;
  110.  
  111.     if (_beginthread(pfnThread,NULL,0x4000,pvParm)==-1)
  112.     {
  113.         free(pvParm);
  114.         WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,
  115.                       "The thread could not be created (openPlayWavThread)", "Error",
  116.                       0, MB_OK | MB_ICONEXCLAMATION | MB_MOVEABLE);
  117.         return;
  118.     }
  119. }
  120.  
  121. Edwin `can somebody tell me why this thread sometimes doesn't stop when
  122.        I'm playing a large wavfile?' G.
  123.  
  124. --
  125. Edwin Groothuis          OS/2: Drag me, drop me, make me feel like an object!
  126. 2:284/205.1@fidonet      
  127. edwin@mavetju.iaehv.nl   URL: http://www.iaehv.nl/users/mansion/edwin.html
  128.